﻿using System;
using System.Collections.Generic;
using System.Text;
using Chaliy.DbPro.Generators.TextAuthoring.Configuration;

namespace Chaliy.DbPro.Generators.TextAuthoring
{
	public class RandomTextAuthorFactory
	{
		#region Fields

		private readonly TextConfiguration configuration;		

		#endregion

		#region Constructors

		public RandomTextAuthorFactory(TextConfiguration configuration)
		{
			if (configuration == null)
			{
				throw new ArgumentNullException("configuration");
			}
			this.configuration = configuration;
		}

		#endregion

		#region Properties

		protected TextConfiguration Configuration
		{
			get 
			{
				return this.configuration; 
			}
		} 

		#endregion

		#region Methods

		public ITextAuthor Create()
		{
			IWordAuthor wordAuthor = new RandomWordAuthor(
				new ListTermAccessor(this.Configuration.Word.Samples)
				);

			ISentanceAuthor sentanceAuthor = new RandomSentanceAuthor(
				new ListTermAccessor(this.Configuration.Sentance.Separators),
				new ListTermAccessor(this.Configuration.Sentance.Comas),
				wordAuthor
				) 
				{
					MinLength = this.Configuration.Sentance.MinLength,
					MaxLength = this.Configuration.Sentance.MaxLength 
				};

            IParagraphAuthor paragraphAuthor = new RandomParagraphAuthor(
                sentanceAuthor
                )
                {
                    MinLength = this.Configuration.Paragraph.MinLength,
                    MaxLength = this.Configuration.Paragraph.MaxLength
                };

			return new TextAuthor(paragraphAuthor);
		}

		#endregion
	}
}
